// Created by wangliang on 2025/3/4.
import 'package:flutter_app_demo/model/account.dart';
import 'package:flutter_app_demo/model/user_info.dart';
import 'package:flutter_app_demo/net/http_agent.dart';

class CommonApi {
  static const refreshTokenUrl = "api/v1/user/token/refresh";

  static Future<void> userCodeSend(String phone, String purpose, String randstr, String ticket) async {
    Map<String, dynamic> params = {};
    params["phone"] = phone;
    params["purpose"] = purpose;
    params['country_code'] = '86';
    params['randstr'] = randstr;
    params['ticket'] = ticket;
    String url = "/api/v1/user/code/send";
    return await HttpAgent.instance.doPostRequest(url, params);
  }

  static Future<Account?> userLogin(String phone, String code) async {
    Map<String, dynamic> params = {};
    params["code"] = code;
    params["phone"] = phone;
    String url = "/api/v1/user/login";
    return await HttpAgent.instance.doPostRequest(url, params);
  }

  static Future<Account?> refreshToken(String refreshToken) async {
    Map<String, dynamic> params = {};
    params["refresh_token"] = refreshToken;
    String url = refreshTokenUrl;
    return await HttpAgent.instance.doPostRequest(url, params);
  }

  static Future<UserInfo?> userInfo() async {
    String url = "/api/v1/user/info";
    return await HttpAgent.instance.doGetRequest(url, null);
  }
}
